<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function json($code=0,$message='',$data=[])
{
    $res=[
        'code' => $code,
        'message'=>$message,
        'data'=>$data
    ];
    exit(json_encode($res,JSON_UNESCAPED_UNICODE));
}

function json_wang($code=0,$message='',$data=[])
{
    $res=[
        'errno' => $code,
        'message'=>$message,
        'data'=>$data
    ];
    exit(json_encode($res,JSON_UNESCAPED_UNICODE));
}

//获取当前域名及根路径
function base_url(){

    $request=\think\facade\Request::instance();
    $path=$request->root(true);
    if (strpos($path,'index.php')){
        $path=substr($path,0,strlen($path)-9);
    }
    return $path;
}

//获取七天的数据
function getLately7days()
{
    $res=[];
    $sec=time();
    for ($i=0;$i<7;$i++){
        array_push($res,date('Y-m-d',$sec));
        $sec-=86400;
    }
    //让数据倒叙
    return array_reverse($res);
}